﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Factories;
using LinFu.IoC.Interfaces;

namespace CoreEx.Common.Repository.Implementation
{
    public class RepositoryTypeDescriptorPreProcessor : IPreProcessor
    {
        public void Preprocess(IServiceRequest request)
        {
            if (request.ArgumentTypes.Count() > 0 && request.ArgumentTypes.First() == typeof(Type))
                if (request.ProposedArguments.First() == typeof(IRepository))
            {
                request.ActualFactory =
                    new FunctorFactory(r => new RepositoryTypeDescriptor((Type) request.ProposedArguments.First()));                    
            }            
        }
    }
}
